#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>

using namespace std;

int minSwaps(string s) {
    int res = 0, cnt = 0;
    int j = s.size() - 1;
    for (auto c : s)
    {
        if (c == '[')
            cnt++;
        else if (cnt > 0)
            cnt--;
        else
        {
            while (s[j] == ']')
                j--;
            s[j] = ']';
            res++;
            cnt++;
        }
    }
    return res;
}

